/*
 * Copyright (c) 2025 Huawei Device Co., Ltd.
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

import 'package:flutter/services.dart';
import 'package:flutter_test/flutter_test.dart';
import 'package:hadss_knock_share/hadss_knock_share.dart';

void main() {
  const areaMethodChannel = MethodChannel('hadss_knock_share');

  TestWidgetsFlutterBinding.ensureInitialized();
  setUp(() {
    // 模拟 MethodChannel 调用
    TestDefaultBinaryMessengerBinding.instance?.defaultBinaryMessenger
        .setMockMethodCallHandler(
      areaMethodChannel,
      (MethodCall methodCall) async {
        if (methodCall.method == 'canUseKnockShare') {
          return true;
        } else if (methodCall.method == 'addKnockShareListener') {
          expect(methodCall.method, 'addKnockShareListener');
        } else if (methodCall.method == 'removeKnockShareListener') {
          expect(methodCall.method, 'removeKnockShareListener');
        } else if (methodCall.method == 'setKnockShareData') {
          expect(methodCall.arguments, isNotNull);
        }
        return null;
      },
    );
  });

  tearDown(() {
    TestDefaultBinaryMessengerBinding.instance?.defaultBinaryMessenger
        .setMockMethodCallHandler(
      areaMethodChannel,
      null,
    );
  });

  // 测试 canUseKnockShare 方法
  test('canUseKnockShare test', () async {
    var knockSharePlugin = KnockShare();
    var canUseKnockShare = await knockSharePlugin.canUseKnockShare();
    expect(canUseKnockShare, true);
  });

  // 测试 onKnockShare 方法
  test('onKnockShare test', () {
    var knockSharePlugin = KnockShare();
    knockSharePlugin.onKnockShare();
  });

  // 测试 offKnockShare 方法
  test('offKnockShare test', () {
    var knockSharePlugin = KnockShare();
    knockSharePlugin.offKnockShare();
  });

  // 测试 setKnockShareData 方法
  test('setKnockShareData test', () {
    var knockSharePlugin = KnockShare();
    var shareBean = SharedRecord(UniformDataType.jpeg);
    shareBean.thumbnailUri = "file:data";
    shareBean.uri = "file:data";
    knockSharePlugin.setKnockShareData(SharedData(shareBean),
        isAutoClean: true);
  });
}
